home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / libg_261.zip / libg_261 / libg++ / src / gen / intVec.hP < prev    next >
Text File  |  1992-04-14  |  3KB  |  81 lines

  1. /*  : light weight Vector: This will simply reuse code from  */
  2. /* a int Vec, which was genclassed from the Vec libg++ class.     */
  3. /* The classes generated from this file will all be derived classes */
  4. /* from class VoidVec or intVec.  No .cc file is generated.  So     */
  5. /* it costs nothing to use these type-safe Vectors. Only member     */
  6. /* functions needing type casting are re-defined.                   */
  7. /*  */
  8.  
  9. #ifndef _<T>Vec_h
  10. #define _<T>Vec_h 1
  11.  
  12. #include "int.Vec.h"
  13. #include "<T>.defs.h"
  14.  
  15.  
  16. #ifndef _<T>_typedefs
  17. #define _<T>_typedefs 1
  18. typedef void (*<T>Procedure)(<T> );
  19. typedef <T>  (*<T>Mapper)(<T> );
  20. typedef <T>  (*<T>Combiner)(<T> , <T> );
  21. typedef int  (*<T>Predicate)(<T> );
  22. typedef int  (*<T>Comparator)(<T> , <T> );
  23. #endif
  24.  
  25. class <T>Vec : public intVec
  26. {
  27. protected:
  28.   <T>Vec(int l, <T>* d) : (l, (int*) d) {};
  29. public:
  30.   <T>Vec() {};
  31.   <T>Vec(int l) : (l) {};
  32.   <T>Vec(int l, <T&> fill_value) : (l, fill_value) {};
  33.   <T>Vec(<T>Vec& v) : (v) {};
  34.   <T>Vec(intVec& v) {fake_copy(v, s, len);}
  35.   ~<T>Vec() {};
  36.  
  37.   <T>Vec& operator = (<T>Vec& a)
  38.            {return (<T>Vec&) intVec::operator= (a);}
  39.   <T>Vec  at(int from, int n) {return (<T>Vec) intVec::at(from, n);}
  40.  
  41.   <T>&    operator [] (int n) {return (<T>&)intVec::operator[] (n);}
  42.   <T>&    elem(int n) {return (<T>&)intVec::elem(n);}
  43.  
  44.   friend <T>Vec   concat(<T>Vec& a, <T>Vec& b);
  45.   friend <T>Vec   map(<T>Mapper f, <T>Vec & a);
  46.   friend <T>Vec   merge(<T>Vec & a, <T>Vec & b, <T>Comparator f);
  47.   friend <T>Vec   combine(<T>Combiner f, <T>Vec & a, <T>Vec & b);
  48.   friend <T>Vec   reverse(<T>Vec& a);
  49.  
  50.   void sort(<T>Comparator f);
  51.   void apply(<T>Procedure f);
  52.   <T> reduce(<T>Combiner f, <T> base);
  53. };
  54.  
  55. inline <T>Vec concat(<T>Vec& a, <T>Vec& b)
  56. {return (<T>Vec)concat((intVec&)a, (intVec&)b);}
  57.  
  58. inline <T>Vec   map(<T>Mapper f, <T>Vec & a) {
  59.   return (<T>Vec)map((intMapper)f, (intVec&)a); }
  60.  
  61. inline <T>Vec   merge(<T>Vec & a, <T>Vec & b, <T>Comparator f) {
  62.   return (<T>Vec)merge((intVec&)a, (intVec&)b, (intComparator)f); }
  63.  
  64. inline <T>Vec   combine(<T>Combiner f, <T>Vec & a, <T>Vec & b) {
  65.   return (<T>Vec)combine((intCombiner)f, (intVec&)a, (intVec&)b); }
  66.  
  67. inline <T>Vec reverse(<T>Vec& a) {
  68.   return (<T>Vec)reverse((intVec&)a);}
  69.  
  70. inline void <T>Vec::sort(<T>Comparator f) {
  71.   intVec::sort((intComparator) f); }
  72.  
  73. inline void <T>Vec::apply(<T>Procedure f) {
  74.   intVec::apply((intProcedure) f); }
  75.  
  76. inline <T> <T>Vec::reduce(<T>Combiner f, <T> base) {
  77.   return (<T>)intVec::reduce((intCombiner)f, base);}
  78.  
  79. #endif /* conditional include */
  80.  
  81.